package github.leavesczy.reactivehttpsamples.core.viewmodel.addbridge

import androidx.lifecycle.MutableLiveData
import github.leavesczy.reactivehttpsamples.base.BaseViewModel
import github.leavesczy.reactivehttpsamples.core.mode.BridgeRecordItem
import github.leavesczy.reactivehttpsamples.core.mode.MeasureModelBodyData

class AddBridgeModel : BaseViewModel() {

    val bridgeAdd = MutableLiveData<Any?>()
    val bridgeDetail = MutableLiveData<BridgeRecordItem>()
    val bridgeMeasureBodyData = MutableLiveData<MeasureModelBodyData>()

    fun requestBridgeAdd(params: MutableMap<String, Any>) {
        remoteDataSource.enqueueLoading({
            requireBridgeAdd(createJsonBody(params))
        }) {
            onSuccess {
                bridgeAdd.value = it
            }

        }
    }


    fun requestBridgeDetail(recordId: Long) {
        val params = mutableMapOf<String, Any>()
        params.put("recordId", recordId)
        remoteDataSource.enqueueLoading({
            requireBridgeDetail(createJsonBody(params))
        }) {
            onSuccess {
                bridgeDetail.value = it
            }

        }
    }

    fun requestBridgeMeasureList(bridgeCode: String, sampleType: String) {
        remoteDataSource.enqueueLoading({
            val map = mutableMapOf<String, Any>()
            map.put("bridgeCode", bridgeCode)
            map.put("sampleType", sampleType)
            requireBridgeMeasureList(createJsonBody(map))
        }) {
            onSuccess {
                bridgeMeasureBodyData.value = it
            }

        }
    }
}